package maze;

import java.util.Stack;

public class MazeMover implements MazeMoveListener{

	Stack <command> moves = new Stack<command>();
	command e = null;
	
	@Override
	public void moveNorth(Maze paramMaze) {
		
		e = new MazeMoveCommand(paramMaze,Direction.North);
		e.execute();
		moves.add(e);
		
	}

	@Override
	public void moveSouth(Maze paramMaze) {
		e = new MazeMoveCommand(paramMaze,Direction.South);
		e.execute();
		moves.add(e);
		
	}

	@Override
	public void moveEast(Maze paramMaze) {
		e = new MazeMoveCommand(paramMaze,Direction.East);
		e.execute();
		moves.add(e);
		
	}

	@Override
	public void moveWest(Maze paramMaze) {
		e = new MazeMoveCommand(paramMaze,Direction.West);
		e.execute();
		moves.add(e);
		
	}

	@Override
	public void undoMove() {
		
		if(!moves.empty()) {
			e = moves.pop();
			if(e instanceof UndoableCommand) {			
				((UndoableCommand)e).undo();
			}
			
		}
		
	}

}
